<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>axios的处理链流程</title>
  </head>
  <body></body>

  <script src="https://cdn.bootcss.com/axios/0.19.0/axios.js"></script>
  <script>
    const instance = axios.create({
      baseURL: "http://localhost:3000",
      timeOut: 40000,
    });

    instance.interceptors.request.use(
      (config) => {
        console.log("request intercepteds success");
        return config;
      },
      (error) => {
        console.log("request intercepteds error");
        return Promise.reject(error);
      }
    );

    instance.interceptors.response.use(
      (response) => {
        console.log("response intercepteds success");
        return response.data;
      },
      (error) => {
        console.log("response intercepteds error");
        return Promise.reject(error);
      }
    );

    instance({
      url: "/posts",
    }).then((res) => console.log(res));
  </script>
</html>
